package main

import (
	"golang.org/x/tour/pic"
	"image"
	"image/color"
)

type Image struct {
	width  int
	height int
	pixels [][]uint8
}

func (p *Image) ColorModel() color.Model { return color.RGBAModel }

func (p *Image) Bounds() image.Rectangle { return image.Rect(0, 0, p.width, p.height) }

func (p *Image) At(x, y int) color.Color {
	return color.RGBA{p.pixels[x][y], p.pixels[x][y], p.pixels[x][y], 255}
}

func Pic(dx, dy int) [][]uint8 {
	s := make([][]uint8, dy)

	for y := 0; y < dy; y++ {
		s[y] = make([]uint8, dx)
		for x := 0; x < dx; x++ {
			s[y][x] = uint8(x * y)
		}
	}

	return s
}

func main() {
	pixels := Pic(200, 200)
	m := Image{200, 200, pixels}
	pic.ShowImage(&m)
}
